<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Api\BaseController;
use App\Repositories\ConfigRepository;
use App\Support\Data;
use Illuminate\Http\Request;

class ConfigController extends BaseController {

	protected $model, $data;

	public function __construct(ConfigRepository $config, Data $data) {
		parent::__construct();

		$this->model = $config;
		$this->data = $data;
	}

	public function user() {
		return $this->response->withSuccess($this->data->getInfo());
	}

	public function setUser(Request $request) {
		$this->data->setInfo($request->only(['content']));
		return $this->response->withNoContent();
	}

	public function resume() {
		$content = $this->data->getResume();
		$array = $this->model->getResumeConfig();
		unset($array['password']);
		$array['content'] = $content;
		return $this->response->withSuccess($array);
	}

	public function setResumeInfo(Request $request) {
		$this->model->update($request->only(['nopwd', 'password']));
		$this->data->setResume($request->only(['content']));
		return $this->response->withNoContent();
	}

	public function setContactMe(Request $request) {
		$this->validate($request, [
			'weibo' => 'required',
			'email' => 'required',
			'wechat' => 'required',
			'github' => 'required',
		]);
		$this->model->update($request->only(['weibo', 'email', 'wechat', 'github']));
		return $this->response->withNoContent();
	}

	public function setShowConfig(Request $request) {
		$this->validate($request, [
			'config' => 'required',
		]);
		$this->model->update($request->only(['config']));
		return $this->response->withNoContent();
	}

	public function setWebsiteSeo(Request $request) {
		$this->model->update($request->only(['say', 'title', 'keywords', 'description']));
		return $this->response->withNoContent();
	}

	public function clearCache() {
		$this->model->clearCache();
		return $this->response->withNoContent();
	}
}
